# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import time
import psutil
import commands


def read_current_flow(password='Vdin1234', ip='1.1.1.1', oid='ifInOctets.777'):
    cmd = 'snmpwalk -v 2c -c %s %s %s' % (password, ip, oid)
    status, result = commands.getstatusoutput(cmd)
    if status != 0:
        return "Error, %s" % result
    return result

while True:
    time_str = time.strftime("%H%M")
    oids = ['ifInOctets.777', 'ifOutOctets.777', 'ifInOctets.1025', 'ifOutOctets.1025']
    results = []
    for oid in oids:
        result = int(read_current_flow(oid=oid).split()[-1])
        results.append(result)
    deltas = ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00',
              '06:00', '07:00', '08:00', '09:00', '10:00', '11:00',
              '12:00', '13:00', '14:00', '15:00', '16:00', '17:00',
              '18:00', '19:00', '20:00', '21:00', '22:00', '23:00']
    # [ str(i)+':00' if i>=10 else '0'+str(i)+':00' for i in range(24)] 代替上式
    if time_str in deltas:
        # 记录数据库
        pass
